package com.example.medicine.controller;

import com.example.medicine.Bean.SystemRole;
import com.example.medicine.Mapper.SystemRoleMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/systemrole")
public class SystemRoleController {
    @Autowired SystemRoleMapper SystemRoleMapper;

    /**
     * 接收SystemRoleList请求，返回数据库的Team表内的所有内容，格式为json
     * @return
     */
    @RequiresPermissions("角色管理")
    @GetMapping("/")
    public List<SystemRole> getSystemroleList(){
        log.info("getSystemroleList获取角色信息");
        return SystemRoleMapper.getAll();
    }

    /**
     * 接收insertSystemRole请求，向SystemRole中插入内容
     */
    @RequiresPermissions("角色管理")
    @PostMapping("/")
    public void insertSystemrole(@RequestBody SystemRole systemrole){
        log.info("insertSystemrole添加角色start");
        SystemRoleMapper.insert(systemrole);
        log.info("insertSystemrole添加角色end");
    }

    /**
     * 接收updateSystemRole请求，根据ID值更新SystemRole内容
     */
    @RequiresPermissions("角色管理")
    @PutMapping("/")
    public void updateSystemrole(@RequestBody SystemRole systemrole){
        log.info("updateSystemrole修改角色信息start");
        SystemRoleMapper.update(systemrole);
        log.info("updateSystemrole修改角色信息end");
    }
    @RequiresPermissions("角色管理")
    @DeleteMapping("/{id}")
    public void deleteSystemrole(@PathVariable String id){
        log.info("deleteSystemrole角色删除");
        SystemRoleMapper.deleteById(id);
    }
}
